package com.soos.plugin.mybatis.log.spring.boot.autoconfigure;

import com.soos.plugin.mybatis.log.spring.boot.interceptor.MybatisLogInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author SOS
 */
@Component
@EnableConfigurationProperties(MybatisLogProperties.class)
public class MybatisLogAutoConfiguration {

    private static final Logger LOGGER = LoggerFactory.getLogger(MybatisLogAutoConfiguration.class);

    @Autowired
    private MybatisLogProperties properties;


    @Bean
    @ConditionalOnMissingBean(MybatisLogInterceptor.class)
    public MybatisLogInterceptor mybatisLogInterceptor() {
        MybatisLogInterceptor interceptor = null;
        if (properties.isEnable()) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("初始化MybatisLogInterceptor");
            }
            interceptor = new MybatisLogInterceptor();
        }
        return interceptor;
    }

}
